package com.local.goods.rabbitmq;


import com.local.goods.constants.GoodsConstants;
import com.local.goods.pojo.GoodsESDoc;
import com.local.goods.service.GoodsService;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 商品es数据消费者，监听goods增删改队列，将goods的增删改同步至es文档
 */

@Component
public class GoodsESConsumer {

    @Autowired
    private GoodsService goodsService;

    /**
     * 监听“更新队列”，同步对es的文档进行更新。如果文档不存在，则新增；如果文档存在，则更新
     * @param idString: 1 || 1,2,3
     */
    @RabbitListener(queuesToDeclare = @Queue(GoodsConstants.GOODS_ES_UPDATE_QUEUE))
    public void goodsESUpdateQueueConsumer(String idString) {
        goodsService.updateSearchDocData(idString);
    }


    /**
     * 监听“删除队列”，同步对es的文档进行删除
     * @param idString: 1 || 1,2,3
     */
    @RabbitListener(queuesToDeclare = @Queue(GoodsConstants.GOODS_ES_DELETE_QUEUE))
    public void goodsESDeleteQueueConsumer(String idString) {
        goodsService.deleteSearchDocData(idString);
    }

}
